<template>
  <iframe v-if="url" :src="url" frameborder="0" width="100%" height="800px" scrolling="auto"></iframe>
</template>

<script>

import TokenStorageUtil from "../../utils/TokenStorageUtil";

export default {
  name: 'IframePageContent',
  inject: ['closeCurrent'],
  props: {
    meta: Object
  },
  data() {
    return {
      url: null,
    }
  },
  created() {
    this.goUrl()
  },
  methods: {
    goUrl() {
      let url = this.meta.url
      if (url !== null && url !== undefined) {
        this.url = url
        if (this.meta.internalOrExternal) {
          this.closeCurrent()
          //外部url加入token
          let tokenStr = '${token}'
          if (url.indexOf(tokenStr) !== -1) {
            let token = TokenStorageUtil.get()
            this.url = url.replace(tokenStr, token)
          }
          window.open(this.url)
        }
      }
    }
  }
}
</script>
